<template>
  <sys-page ref="page" :columns="columns" :model="model" :loader="loader" :label-width="null" @add="onAdd" showAddBtn
            :query-props="{expandAble: false}">
    <!-- 表单查询 -->
    <template v-slot:form>
      <el-form-item label="报表名称">
        <el-input v-model="model.reportName" placeholder="报表名称" clearable></el-input>
      </el-form-item>
    </template>

    <template v-slot:enableFlag="{row}">
      <el-tag size="small" :type="row.enableFlag ? 'success' : 'danger'">{{row.enableFlag ? '启用' : '禁用'}}</el-tag>
    </template>
    <template v-slot:ctrl="scope">
      <sys-ctrl :btns="btns" :scope="scope"></sys-ctrl>
    </template>

  </sys-page>
</template>

<script>
import {postReportList, postReportDelete} from "@/api/report"
import edit from './edit'

function getColumns() {
  return [
    {type: 'selection', align: 'center'},
    {type: 'index', label: '序号', align: 'center'},
    {prop: 'reportName', label: '报表名称', align: 'center', minWidth: 120, showOverflowTooltip: true, display: true},
    {prop: 'enableFlag', label: '状态', align: 'center', minWidth: 120, showOverflowTooltip: true, display: true},
    {prop: 'createBy', label: '创建人', align: 'center', minWidth: 120, showOverflowTooltip: true, display: true},
    {prop: 'createTime', label: '创建时间', align: 'center', minWidth: 120, showOverflowTooltip: true, display: true},
    {prop: 'updateTime', label: '更新时间', align: 'center', minWidth: 120, showOverflowTooltip: true, display: true},
    {prop: 'ctrl', label: '操作', width: '180px', fixed: 'right', align: 'center'}
  ]
}

export default {
  name: 'report',
  cnName: 'report',
  data() {
    return {
      model: {
        reportName: ''
      },
      columns: getColumns(),
      btns: [
        {
          label: '编辑',
          click: row => {
            this.onEdit(row)
          }
        },
        {
          label: '预览',
          click: scope => {
            this.onPreview(scope.row)
          }
        },
        {
          label: '设计',
          click: scope => {
            this.onDesign(scope.row)
          }
        },
        {
          label: '分享',
          click: scope => {
            this.onShare(scope.row)
          }
        },
        {
          label: '复制',
          click: scope => {
            this.onCopy(scope.row)
          }
        },
        {
          label: '删除',
          click: scope => {
            this.onDelete(scope.row)
          }
        }
      ]
    }
  },
  methods: {
    async loader(model) {
      return postReportList(model)
    },
    onAdd() {
      this.$refs.page.setDialog({
        title: '新增',
        comp: edit,
        props: {
        }
      })
    },
    onEdit(row) {
      const {id} = row
      this.$refs.page.setDialog({
        title: '修改',
        comp: edit,
        props: {
          id: id
        }
      })
    },
    onDelete(row) {
      this.doDelete([row.id])
    },
    doDelete(ids) {
      this.$confirm('确定进行删除操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        postReportDelete(ids).then(_ => {
          this.$notify.success('删除成功!')
          this.$refs.page.reload()
        })
      })
    }
  }
}
</script>

